Skip to content

fix(analytics): use ThreadPoolExecutor for engage pagination so it works on AWS Lambda - #86

Draft
rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-378-utils-59-export_people-raises
Draft

rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-378-utils-59-export_people-raises

Conversation

@rahul-mixpanel

@rahul-mixpanel rahul-mixpanel commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On AWS Lambda, export_people() / query_engage() fail with FileNotFoundError: [Errno 2] No such file or directory, raised while creating a multiprocessing.pool.ThreadPool. The import paths (import_events, import_people, people_operation, group imports via _dispatch_batches) also use ThreadPool and would fail the same way.

Root cause: ThreadPool is built on multiprocessing.Pool, which creates POSIX semaphores (SemLock) through /dev/shm. Lambda has no /dev/shm, so making the pool fails.

Fix: both places now use concurrent.futures.ThreadPoolExecutor, which only uses threading:

  • ConcurrentPaginator._concurrent_flatmap (engage pagination) uses executor.map. It keeps result order and the read_pool_size concurrency, and still passes worker exceptions to the caller.
  • MixpanelUtils._dispatch_batches (batch imports) submits each batch and waits for all of them with executor.shutdown(wait=True). As before, _async_response_handler_callback runs only after a successful _send_batch, and _send_batch errors are handled the same way (logged / written to import_backup.txt, not raised to the caller). Concurrency still comes from pool_size.

The public API, output files and request payloads don't change.

Tests

New tests simulate Lambda by making multiprocessing SemLock creation raise FileNotFoundError:

  • tests/test_paginator.py: pages come back in order and fetch_all works without multiprocessing semaphores.
  • tests/test_dispatch_batches.py: every batch is sent and the response callback runs once per batch.

Both Lambda tests fail on master and pass with this change. Full suite: 62 passed.

Not included

Cancelling queued pages after the first failure (shutdown(cancel_futures=True)). master doesn't do this either, so this PR keeps the current behaviour.

Related to #59 · Linear: SDK-378

🤖 Generated with Claude Code

…rks on AWS Lambda

multiprocessing.pool.ThreadPool creates POSIX semaphores, which need
/dev/shm. AWS Lambda has no /dev/shm, so query_engage/export_people
failed with FileNotFoundError while creating the pool.
concurrent.futures.ThreadPoolExecutor only uses threading primitives
and keeps the same ordering and concurrency.

Related to #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown

SDK-378

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no actionable new issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issues were found.

Reviews (2) · Last reviewed commit: "fix(analytics): use ThreadPoolExecutor f..." · Reviewed by Greptile

… on AWS Lambda

_dispatch_batches (used by import_events, people_operation and the other
import paths) also used multiprocessing.pool.ThreadPool, which fails on
Lambda for the same /dev/shm reason. Submit batches to a
ThreadPoolExecutor and wait for them on shutdown; the response callback
still runs only on success and _send_batch errors stay handled as before.

Related to #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant